package com.pfzy.ui.activity.dragsort;

import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.module.DraggableModule;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.pfzy.ui.R;

import java.util.List;

/// http://www.manongjc.com/detail/64-gxcnmynkdgxfsfp.html
public class DragSortAdapter extends BaseQuickAdapter<DragSortEntity, BaseViewHolder> implements DraggableModule {
    private OnItemClickListener onItemClickListener;// 事件回调监听

    public DragSortAdapter(@Nullable List<DragSortEntity> data) {
        super(R.layout.item_drag_sort, data);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, DragSortEntity item) {
        helper.setText(R.id.item_drag_sort_name, item.getName());
        helper.setImageDrawable(R.id.item_drag_sort_imge, item.getDrawable());

//        // 删除
//        int itemPosition = getItemPosition(item);
//        helper.getView(R.id.item_drag_sort_name).setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                getData().remove(itemPosition);
//                notifyDataSetChanged();
//            }
//        });
//
//        // 变换位置
//        helper.getView(R.id.item_drag_sort_imge).setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                onItemClickListener.onItemClick(v, itemPosition);
//            }
//        });
    }

    public interface OnItemClickListener {
        void onItemClick(View view, int position);
    }

    public void setOnItemClickListener(OnItemClickListener listener) {
        this.onItemClickListener = listener;
    }
}

